package it.uniroma2.art.coda.structures;

import it.uniroma2.art.owlart.model.ARTLiteral;
import it.uniroma2.art.owlart.model.ARTNode;
import it.uniroma2.art.owlart.model.ARTURIResource;

/**
 * This class contains a triple of ARTResources representing a RDF Triple
 * 
 * @author Andrea Turbati
 * 
 */
public class ARTTriple {
	private ARTURIResource subjectUri;
	private ARTURIResource predicateUri;
	private boolean isObjARes;
	private ARTURIResource objectUri;
	private ARTLiteral objectLiteral;
	private double confidence;

	/**
	 * @param subj
	 *            the subject of the triple
	 * @param pred
	 *            the predicate of the triple
	 * @param obj
	 *            the object of the triple
	 * @param confidence
	 *            the confidence value for this triple
	 */
	public ARTTriple(ARTNode subj, ARTNode pred, ARTNode obj, double confidence) {
		this.subjectUri = subj.asURIResource();
		this.predicateUri = pred.asURIResource();
		if (obj.isLiteral()) {
			this.objectUri = null;
			this.objectLiteral = obj.asLiteral();
			this.isObjARes = false;
		} else { // obj.isURIResource()
			this.objectUri = obj.asURIResource();
			this.objectLiteral = null;
			this.isObjARes = true;
		}
	}

	/**
	 * @param subj
	 *            the subject of the triple
	 * @param pred
	 *            the predicate of the triple
	 * @param obj
	 *            the object of the triple
	 * @param confidence
	 *            the confidence value for this triple
	 */
	public ARTTriple(ARTURIResource subj, ARTURIResource pred, ARTURIResource obj, double confidence) {
		this.subjectUri = subj;
		this.predicateUri = pred;
		this.objectUri = obj;
		this.objectLiteral = null;
		this.isObjARes = true;
		this.confidence = confidence;
	}

	/**
	 * @param subj
	 *            the subject of the triple
	 * @param pred
	 *            the predicate of the triple
	 * @param obj
	 *            the object of the triple
	 * @param confidence
	 *            the confidence value for this triple
	 */
	public ARTTriple(ARTURIResource subj, ARTURIResource pred, ARTLiteral obj, double confidence) {
		this.subjectUri = subj;
		this.predicateUri = pred;
		this.objectUri = null;
		this.objectLiteral = obj;
		this.isObjARes = false;
		this.confidence = confidence;
	}

	/**
	 * Get the subject of the triple
	 * 
	 * @return the subject of the triple
	 */
	public ARTURIResource getSubjectUri() {
		return subjectUri;
	}

	/**
	 * Get the predicate of the triple
	 * 
	 * @return the predicate of the triple
	 */
	public ARTURIResource getPredicateUri() {
		return predicateUri;
	}

	/**
	 * Check if the object is a URI or a Literal
	 * 
	 * @return true if the object is a URI, false otherwise (it is a literal)
	 */
	public boolean isObjARes() {
		return isObjARes;
	}

	/**
	 * Get the object (URI Resource) of the triple. Should be used only if {@link #isObjARes()} returns true
	 * 
	 * @return the object (URI Resource) of the triple or null if the object is a literal
	 */
	public ARTURIResource getObjectUri() {
		return objectUri;
	}

	/**
	 * Get the object (literal) of the triple. Should be used only if {@link #isObjARes()} returns false
	 * 
	 * @return the object (literal) of the triple or null if the object is a URI
	 */
	public ARTLiteral getObjectLiteral() {
		return objectLiteral;
	}

	/**
	 * Get the confidence value
	 * 
	 * @return the confidence value
	 */
	public double getConfidence() {
		return confidence;
	}
}
